package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Department;
import cn.wolfcode.mapper.DepartmentMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public int insertDepartment(Department record) {
        departmentMapper.insert(record);
        return 0;
    }

    @Override
    public int deleteDepartment(Long id) {
        departmentMapper.deleteByPrimaryKey(id);
        return 0;
    }

    @Override
    public int updateDepartment(Department record) {
        return departmentMapper.updateByPrimaryKey(record);
    }

    @Override
    public Department selectDepartment(Long id) {
        return departmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Department> selectDepartmentList() {
        return departmentMapper.selectAll();
    }



    @Override
    public PageInfo<Department> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo<Department>(departmentMapper.queryList(qo));
    }
}
